<?php

namespace App\Models;


use App\Tool\Helper;

/**
 * App\Models\OcrUrine
 *
 * @property int $id
 * @property int|null $ocr_id 化验单id
 * @property int|null $user_id 用户id
 * @property string|null $color 颜色（Color）
 * @property string|null $clarity 清晰度（Clarity）
 * @property string|null $glu 尿糖（GLU）
 * @property string|null $pro 尿蛋白（PRO）
 * @property string|null $malb 尿微量白蛋白（MALB）
 * @property string|null $bil 尿胆红素（BIL）
 * @property string|null $uro 尿胆原（URO）
 * @property string|null $ph 尿PH（PH）
 * @property string|null $sg 尿比重（SG）
 * @property string|null $ob 尿隐血（OB）
 * @property string|null $ket 尿酮体（KET）
 * @property string|null $nit 亚硝酸盐（NIT）
 * @property string|null $leu 白细胞酶活性（LEU）
 * @property string|null $wbc 尿白细胞计数（WBC）
 * @property string|null $wbcc 白细胞团（WBCC）
 * @property string|null $rbc 尿红细胞计数（RBC）
 * @property string|null $cre 尿肌酐（CRE）
 * @property string|null $a_c 白蛋白肌酐比（A/C）
 * @property string|null $ec 上皮细胞计数（EC）
 * @property string|null $cast 管型计数（CAST）
 * @property string|null $uncc 未分类管型（UNCC）
 * @property string|null $bact 细菌计数（BACT）
 * @property string|null $ylc 酵母菌（YLC）
 * @property string|null $xtal 结晶（XTAL）
 * @property string|null $uncx 未分类结晶（UNCX）
 * @property string|null $ls 尿沉渣（LS）
 * @property string|null $sperm 精子检查（SPERM）
 * @property string|null $musg 黏液丝（MUSG）
 * @property string|null $vc 维生素C（Vc）
 * @property string|null $ny_gx 镜检管型（NY-GX）
 * @property string|null $sg_spcj 镜检上皮细胞（SG-SPCJ）
 * @property string|null $sg_ebcj 镜检红细胞（SG-RBCJ）
 * @property string|null $sg_wbcj 镜检白细胞（SG-WBCJ）
 * @property string|null $sg_hlcj 镜检脓细胞（SG-HLCJ）
 * @property string|null $condct 电导率（Condct）
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine query()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereAC($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereBact($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereBil($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereCast($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereClarity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereColor($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereCondct($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereCre($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereEc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereGlu($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereKet($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereLeu($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereLs($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereMalb($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereMusg($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereNit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereNyGx($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereOb($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereOcrId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine wherePh($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine wherePro($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereRbc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereSg($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereSgEbcj($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereSgHlcj($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereSgSpcj($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereSgWbcj($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereSperm($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereUncc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereUncx($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereUro($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereVc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereWbc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereWbcc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereXtal($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrUrine whereYlc($value)
 * @mixin \Eloquent
 */
class OcrUrine extends Base{

    protected $table = 'ocr_urine';
    public $columnsArr = [
        'color' => '颜色（Color）',
        'clarity' => '清晰度（Clarity）',
        'glu' => '尿糖（GLU）',
        'pro' => '尿蛋白（PRO）',
        'malb' => '尿微量白蛋白（MALB）',
        'bil' => '尿胆红素（BIL）',
        'uro' => '尿胆原（URO）',
        'ph' => '尿PH（PH）',
        'sg' => '尿比重（SG）',
        'ob' => '尿隐血（OB）',
        'ket' => '尿酮体（KET）',
        'nit' => '亚硝酸盐（NIT）',
        'leu' => '白细胞酶活性（LEU）',
        'wbc' => '尿白细胞计数（WBC）',
        'wbcc' => '白细胞团（WBCC）',
        'rbc' => '尿红细胞计数（RBC）',
        'cre' => '尿肌酐（CRE）',
        'a_c' => '白蛋白肌酐比（A/C）',
        'ec' => '上皮细胞计数（EC）',
        'cast' => '管型计数（CAST）',
        'uncc' => '未分类管型（UNCC）',
        'bact' => '细菌计数（BACT）',
        'ylc' => '酵母菌（YLC）',
        'xtal' => '结晶（XTAL）',
        'uncx' => '未分类结晶（UNCX）',
        'ls' => '尿沉渣（LS）',
        'sperm' => '精子检查（SPERM）',
        'musg' => '黏液丝（MUSG）',
        'vc' => '维生素C（Vc）',
        'ny_gx' => '镜检管型（NY-GX）',
        'sg_spcj' => '镜检上皮细胞（SG-SPCJ）',
        'sg_ebcj' => '镜检红细胞（SG-RBCJ）',
        'sg_wbcj' => '镜检白细胞（SG-WBCJ）',
        'sg_hlcj' => '镜检脓细胞（SG-HLCJ）',
        'condct' => '电导率（Condct）',
    ];

    protected $fillable = [
    ];

//    public $timestamps = false;//关闭自动维护
    public function add($item)
    {
        $columnsArr = Helper::reverseArr($this->columnsArr);
        $insertItem = [];
        foreach ($item as $k => $value) {
            $insertItem[$columnsArr[$value['name']] ?? $value['name']] = $value['content'];
        }
        $insertItem['created_at'] = date('Y-m-d H:i:s');
        $insertItem['updated_at'] = $insertItem['created_at'];

        self::insert($insertItem);
    }

    /**
     * 编辑资料
     *
     * @param $id
     * @param $user_id
     * @param $data
     * @return false
     */
    public function edit($id, $user_id, $data)
    {
        $model = self::whereUserId($user_id)
            ->where('id', $id)
            ->first();
        if (empty($model)) return false;

        $model->color = $data['color'] ?? null;
        $model->clarity = $data['clarity'] ?? null;
        $model->glu = $data['glu'] ?? null;
        $model->pro = $data['pro'] ?? null;
        $model->malb = $data['malb'] ?? null;
        $model->bil = $data['bil'] ?? null;
        $model->uro = $data['uro'] ?? null;
        $model->ph = $data['ph'] ?? null;
        $model->sg = $data['sg'] ?? null;
        $model->ob = $data['ob'] ?? null;
        $model->ket = $data['ket'] ?? null;
        $model->nit = $data['nit'] ?? null;
        $model->leu = $data['leu'] ?? null;
        $model->wbc = $data['wbc'] ?? null;
        $model->wbcc = $data['wbcc'] ?? null;
        $model->rbc = $data['rbc'] ?? null;
        $model->cre = $data['cre'] ?? null;
        $model->a_c = $data['a_c'] ?? null;
        $model->ec = $data['ec'] ?? null;
        $model->cast = $data['cast'] ?? null;
        $model->uncc = $data['uncc'] ?? null;
        $model->bact = $data['bact'] ?? null;
        $model->ylc = $data['ylc'] ?? null;
        $model->xtal = $data['xtal'] ?? null;
        $model->uncx = $data['uncx'] ?? null;
        $model->ls = $data['ls'] ?? null;
        $model->sperm = $data['sperm'] ?? null;
        $model->musg = $data['musg'] ?? null;
        $model->vc = $data['vc'] ?? null;
        $model->ny_gx = $data['ny_gx'] ?? null;
        $model->sg_spcj = $data['sg_spcj'] ?? null;
        $model->sg_ebcj = $data['sg_ebcj'] ?? null;
        $model->sg_wbcj = $data['sg_wbcj'] ?? null;
        $model->sg_hlcj = $data['sg_hlcj'] ?? null;
        $model->condct = $data['condct'] ?? null;
        return $model->save();
    }
}
